Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(lib): remove error branch from LUT if it is unreachable #386

Merged
merged 4 commits into from
Jun 2, 2024

Conversation

RustyYato
Copy link
Contributor

Fixes #385

This removes unreachable branches from LUTs in the generated code, so that LLVM can see that the error case is unreachable for lexers like in the linked issue

@jeertmans
Copy link
Collaborator

Hello @RustyYato! Thank you for your PR!

Can you implement a small test that generates the LUT and checks that, indeed, the error branch is removed if it is unreachable?

Tell me if you need help with setting up the test :-)

@jeertmans jeertmans added the enhancement New feature or request label Apr 9, 2024
@RustyYato
Copy link
Contributor Author

Would you like a test like in logos-cli? I think I could extend that to check the codegen of the LUT, or did you have something else in mind?

@RustyYato
Copy link
Contributor Author

friendly ping @jeertmans 😄

@jeertmans
Copy link
Collaborator

Ooos sorry @RustyYato!

yes the easiest way to test this might be to test against the output of the logos-cli. So you can generate a very basic scenario: one lexer that has a useful error branch, and one whose error branch was removed :)

To check that your tests work, you can remove your patch and first check that they fail, then apply your patch and check they now work :)

@RustyYato
Copy link
Contributor Author

Hey, I will be out for the next few days, but I'll get back to this once I'm back. 😀

@RustyYato
Copy link
Contributor Author

Hmm, it looks like the lookup table isn't taken in some cases (specifically the one in the related issue). So there may be some other low hanging fruit to remove error cases. But I'll add a test for one that does use the LUT and solve the other cases separately.

@RustyYato
Copy link
Contributor Author

I've just updated the tests in logos-cli to handle multiple inputs at once, so it becomes easier to add new codegen tests in the future.
LMK if you had something else in mind/

@jeertmans
Copy link
Collaborator

Looks great, thanks @RustyYato!

I have 2 remarks / suggestions:

  • I would rather put those tests in the tests folder, as they are more "integration" tests than logos-cli tests;
  • I think using rstest's fixture might be more readable. You could also build a PathBuf using join methods instead and unwrap it, so we don't use OS-specific separators (I know it works because they will translate / to \\ On Windows, but still).

Don't hesitate to give your opinion on this :-)

@RustyYato
Copy link
Contributor Author

RustyYato commented May 6, 2024

Ok, in that case I think it would be nice to make it easy to add new tests and update old tests if codegen changes.
I reverted my original tests commit, and added a new test function which is parameterized on the codegen directory name, and added an env var BLESS_CODEGEN to update the codegen tests if they need to be updated all at once.
How does that look?

I can rebase the changes right before merging to clean up the history if you would like. I find rebases during reviews make reviewing harder so didn't do that yet.

@RustyYato
Copy link
Contributor Author

friendly ping @jeertmans 🙂

@jeertmans jeertmans changed the title remove error branch from LUT if it is unreachable chore(lib): remove error branch from LUT if it is unreachable Jun 2, 2024
@jeertmans
Copy link
Collaborator

Hey @RustyYato, I am very sorry about my delay, was very busy working on my own projects and work, so I put those reviews on hold.

Anyway, I think your work is great and deserves to be merged! Thanks for your great work on this!

At first, I was waiting because I wanted to think a bit about the best (and cleanest) way to handle those kind tests, but let's merge this and see if we need to improve it (or not) in the future!

@jeertmans jeertmans merged commit 3878dbb into maciejhirsz:master Jun 2, 2024
18 checks passed
@RustyYato RustyYato deleted the remove-unreachable-error branch June 2, 2024 15:51
@RustyYato
Copy link
Contributor Author

Not a problem, thanks for the reviews!

akrantz01 referenced this pull request in akrantz01/antsi Aug 2, 2024
[![Mend
Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [logos](https://logos.maciej.codes/)
([source](https://togithub.com/maciejhirsz/logos)) | dependencies |
patch | `0.14.0` -> `0.14.1` |

---

### Release Notes

<details>
<summary>maciejhirsz/logos (logos)</summary>

###
[`v0.14.1`](https://togithub.com/maciejhirsz/logos/releases/tag/v0.14.1):
0.14.1 - Debug feature and fixes

#### What's Changed

- fix(doc): reset logos2 to logos by
[@&#8203;jeertmans](https://togithub.com/jeertmans) in
[https://github.com/maciejhirsz/logos/pull/372](https://togithub.com/maciejhirsz/logos/pull/372)
- chore(book): add JSON-borrowed parser example by
[@&#8203;jeertmans](https://togithub.com/jeertmans) in
[https://github.com/maciejhirsz/logos/pull/373](https://togithub.com/maciejhirsz/logos/pull/373)
- Add Rc<T> and Arc<T> sources by
[@&#8203;InfiniteCoder01](https://togithub.com/InfiniteCoder01) in
[https://github.com/maciejhirsz/logos/pull/340](https://togithub.com/maciejhirsz/logos/pull/340)
- Fix unicode dot by [@&#8203;RustyYato](https://togithub.com/RustyYato)
in
[https://github.com/maciejhirsz/logos/pull/376](https://togithub.com/maciejhirsz/logos/pull/376)
- chore(docs): cleanup examples by
[@&#8203;jeertmans](https://togithub.com/jeertmans) in
[https://github.com/maciejhirsz/logos/pull/381](https://togithub.com/maciejhirsz/logos/pull/381)
- chore(lib): add debug feature by
[@&#8203;jeertmans](https://togithub.com/jeertmans) in
[https://github.com/maciejhirsz/logos/pull/382](https://togithub.com/maciejhirsz/logos/pull/382)
- Cleanup unused Source features by
[@&#8203;kmicklas](https://togithub.com/kmicklas) in
[https://github.com/maciejhirsz/logos/pull/335](https://togithub.com/maciejhirsz/logos/pull/335)
- chore(deps): bump peaceiris/actions-mdbook from 1 to 2 by
[@&#8203;dependabot](https://togithub.com/dependabot) in
[https://github.com/maciejhirsz/logos/pull/387](https://togithub.com/maciejhirsz/logos/pull/387)
- Fix `Lexer::clone` leak and UB + tests by
[@&#8203;Jakobeha](https://togithub.com/Jakobeha) in
[https://github.com/maciejhirsz/logos/pull/390](https://togithub.com/maciejhirsz/logos/pull/390)
- fix(lib): correctly handle miss for loop in loop by
[@&#8203;lukas-code](https://togithub.com/lukas-code) in
[https://github.com/maciejhirsz/logos/pull/393](https://togithub.com/maciejhirsz/logos/pull/393)
- chore(lib): remove error branch from LUT if it is unreachable by
[@&#8203;RustyYato](https://togithub.com/RustyYato) in
[https://github.com/maciejhirsz/logos/pull/386](https://togithub.com/maciejhirsz/logos/pull/386)
- fix(docs): typo by
[@&#8203;joerivanruth](https://togithub.com/joerivanruth) in
[https://github.com/maciejhirsz/logos/pull/396](https://togithub.com/maciejhirsz/logos/pull/396)
- chore(docs): Adds graph debug documentation to book by
[@&#8203;afreeland](https://togithub.com/afreeland) in
[https://github.com/maciejhirsz/logos/pull/379](https://togithub.com/maciejhirsz/logos/pull/379)
- chore: drop python linting frmo pre-commit-config by
[@&#8203;LeoDog896](https://togithub.com/LeoDog896) in
[https://github.com/maciejhirsz/logos/pull/403](https://togithub.com/maciejhirsz/logos/pull/403)
- refactor: don't use deprecated max_value() method by
[@&#8203;LeoDog896](https://togithub.com/LeoDog896) in
[https://github.com/maciejhirsz/logos/pull/404](https://togithub.com/maciejhirsz/logos/pull/404)
- chore(version): bump logos version to 0.14.1 by
[@&#8203;jeertmans](https://togithub.com/jeertmans) in
[https://github.com/maciejhirsz/logos/pull/409](https://togithub.com/maciejhirsz/logos/pull/409)
- fix(docs): change old 0.14.0 by
[@&#8203;jeertmans](https://togithub.com/jeertmans) in
[https://github.com/maciejhirsz/logos/pull/410](https://togithub.com/maciejhirsz/logos/pull/410)

#### New Contributors

- [@&#8203;InfiniteCoder01](https://togithub.com/InfiniteCoder01) made
their first contribution in
[https://github.com/maciejhirsz/logos/pull/340](https://togithub.com/maciejhirsz/logos/pull/340)
- [@&#8203;RustyYato](https://togithub.com/RustyYato) made their first
contribution in
[https://github.com/maciejhirsz/logos/pull/376](https://togithub.com/maciejhirsz/logos/pull/376)
- [@&#8203;Jakobeha](https://togithub.com/Jakobeha) made their first
contribution in
[https://github.com/maciejhirsz/logos/pull/390](https://togithub.com/maciejhirsz/logos/pull/390)
- [@&#8203;lukas-code](https://togithub.com/lukas-code) made their first
contribution in
[https://github.com/maciejhirsz/logos/pull/393](https://togithub.com/maciejhirsz/logos/pull/393)
- [@&#8203;joerivanruth](https://togithub.com/joerivanruth) made their
first contribution in
[https://github.com/maciejhirsz/logos/pull/396](https://togithub.com/maciejhirsz/logos/pull/396)
- [@&#8203;afreeland](https://togithub.com/afreeland) made their first
contribution in
[https://github.com/maciejhirsz/logos/pull/379](https://togithub.com/maciejhirsz/logos/pull/379)
- [@&#8203;LeoDog896](https://togithub.com/LeoDog896) made their first
contribution in
[https://github.com/maciejhirsz/logos/pull/403](https://togithub.com/maciejhirsz/logos/pull/403)

**Full Changelog**:
maciejhirsz/logos@v0.14...v0.14.1

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined),
Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you
are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update
again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR was generated by [Mend
Renovate](https://www.mend.io/free-developer-tools/renovate/). View the
[repository job log](https://developer.mend.io/github/akrantz01/antsi).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy40NDAuNyIsInVwZGF0ZWRJblZlciI6IjM3LjQ0MC43IiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6W119-->

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unreachable branch in LUTs are still linked to
2 participants